<template>
<div class="layerRtb layerRtb-threecolumn">
    <three-title :title="{name:'新增科目'}"></three-title>
    <div class="layerRtb-scroll thinScroll" v-scrollHeight = "137">
        <div class="analyItem">
            <p class="analyItemTit tx-center">名称 </p>
            <div class="analyItemCon">
                <input class="width200" v-model="projectName" type="text" placeholder="请输入科目内容">
            </div>
        </div>
        <div class="analyItem">
            <p class="analyItemTit tx-center">图片上传</p>
            <div class="analyItemCon">
                <div class="clearfix mt10 fl">
                    <rx-upload
                        class="fl"
                        :data="{id: 11}" :init="{class: 1, mime: 1}"
                        :elStyle="{width:'90px', height: '80px'}"
                        @success="successUpload">
                        <div class="fl uiImgUpload uiImgUpload-gblock mr10">
                            <a href="javascript:">
                                <span type="file" value="" class="file"></span>
                                <em class="bgIcon file-ico"></em>
                            </a>
                        </div>
                    </rx-upload>
                    <rx-viewer  class="fl ml10">
                        <div class="clearfix">
                            <div class="fl mr10">
                                <img :src="projectImgList | smallImg(78, 78)">
                            </div>
                        </div>
                    </rx-viewer>
                </div>
            </div>
        </div>
    </div>
    <div class="layerRtb-footer">
        <div class="tx-center">
            <input type="button" class="uiBtn-normal uiBtn-blue" @click="saveSubjectNew()" value="确定">
        </div>
    </div>
</div>
</template>
<script>
import { mapMutations, mapGetters } from 'vuex'
import { saveSubjectNew } from '../Resources/Api/index'
export default {
    data () {
        return {
            projectName: '', // 科目名称
            projectImgList: '' // 科目图片
        }
    },
    created () {
    },
    computed: {
        ...mapGetters(['leftInfo', 'twoToThreeInfo', 'userInfo'])
    },
    methods: {
        ...mapMutations({
            setUpDatePlate: `SET_UPDATE_PLATE`
        }),
        // 图片上传
        successUpload (value) {
            this.projectImgList = value.src
        },
        saveSubjectNew () {
            if (this.projectImgList === '') {
                this.$message('必须上传图片')
                return false
            }
            if (this.projectName === '') {
                this.$message('科目名称不能为空')
                return false
            }
            let params = {
                userNo: this.userInfo.as_cardNo,
                userName: this.userInfo.as_fullName,
                name: this.projectName,
                img: this.projectImgList
            }
            // 查询服务项科目
            saveSubjectNew(params).then(results => {
                if (results.data.StatusCode === 1) {
                    this.setUpDatePlate()
                    // 关闭弹窗
                    this.$router.push(this.$route.matched[1].path)
                }
            }).catch(error => {
                console.log(error)
            })
        }
    }
}
</script>
<style lang="scss">
    .operButton {
        position:absolute;
        top: 50%;
        right: 10px;
        transform:translateY(-50%);
    }
</style>
